from hashlib import sha256
from sqlalchemy import CHAR, DECIMAL, VARCHAR, Column, Enum, ForeignKey, Integer
from sqlalchemy.orm import declarative_base
MyBase = declarative_base()


class 班级(MyBase):
    __tablename__ = "班级"

    id = Column(Integer, primary_key=True, comment="班级id")
    班级名 = Column(VARCHAR(20), nullable=False, server_default="", comment="班级名")
    field = "id", "班级名"


class 学生(MyBase):
    __tablename__ = "学生"

    id = Column(Integer, primary_key=True, comment="学生id")
    学号 = Column(VARCHAR(20), nullable=False, server_default="", comment="学号")
    姓名 = Column(VARCHAR(20), nullable=False, server_default="", comment="姓名")
    性别 = Column(Enum("男", "女", ""), nullable=False, server_default="", comment="性别")
    班级id = Column(Integer, ForeignKey("班级.id"), comment="班级id")
    政治面貌 = Column(VARCHAR(20), nullable=False, server_default="", comment="政治面貌")
    民族 = Column(VARCHAR(20), nullable=False, server_default="", comment="民族")
    宿舍号 = Column(VARCHAR(20), nullable=False, server_default="", comment="宿舍号")
    field = "id", "学号", "姓名", "性别", "班级id", "政治面貌", "民族", "宿舍号"


class 课程(MyBase):
    __tablename__ = "课程"

    id = Column(Integer, primary_key=True, comment="课程id")
    课程号 = Column(VARCHAR(20), nullable=False, server_default="", comment="课程号")
    课程名 = Column(VARCHAR(20), nullable=False, server_default="", comment="课程名")
    学分 = Column(DECIMAL(5, 1), nullable=False, server_default="1.0", comment="学分")
    field = "id", "课程号", "课程名", "学分"


class 班主任(MyBase):
    __tablename__ = "班主任"

    id = Column(Integer, primary_key=True, comment="班主任id")
    教师号 = Column(VARCHAR(20), nullable=False, server_default="", comment="教师号")
    姓名 = Column(VARCHAR(20), nullable=False, server_default="", comment="姓名")
    性别 = Column(Enum("男", "女", ""), nullable=False, server_default="", comment="性别")
    系统密码 = Column(CHAR(64), nullable=False, comment="系统密码 (SHA-256)",
        server_default=sha256("123456".encode("utf-8")).hexdigest())
    班级id = Column(VARCHAR(20), nullable=False, server_default="", comment="班级id")
    field = "id", "教师号", "姓名", "性别", "系统密码", "班级id"


class 选修(MyBase):
    __tablename__ = "选修"

    id = Column(Integer, primary_key=True, comment="选修id")
    学生id = Column(Integer, ForeignKey("学生.id"), comment="学生id")
    课程id = Column(Integer, ForeignKey("课程.id"), comment="课程id")
    成绩 = Column(DECIMAL(5, 1), nullable=False, server_default="80", comment="成绩")
    field = "id", "学生id", "课程id", "成绩"


class 评价(MyBase):
    __tablename__ = "评价"

    id = Column(Integer, primary_key=True, comment="评价id")
    学生id = Column(Integer, ForeignKey("学生.id"), comment="学生id")
    班主任id = Column(Integer, ForeignKey("班主任.id"), comment="班主任id")
    评语 = Column(VARCHAR(8000), nullable=False, server_default="", comment="评语")
    field = "id", "学生id", "班主任id", "评语"


class 班干(MyBase):
    __tablename__ = "班干"

    id = Column(Integer, primary_key=True, comment="班干id")
    学生id = Column(Integer, ForeignKey("学生.id"), comment="学生id")
    班级id = Column(Integer, ForeignKey("班级.id"), comment="班级id")
    班干名称 = Column(VARCHAR(20), nullable=False, server_default="", comment="班干名称")
    field = "id", "学生id", "班级id", "班干名称"


class 班会(MyBase):
    __tablename__ = "班会"

    id = Column(Integer, primary_key=True, comment="班会id")
    班级id = Column(Integer, ForeignKey("班级.id"), comment="班级id")
    班会内容 = Column(VARCHAR(8000), nullable=False, server_default="", comment="班会内容")
    field = "id", "班级id", "班会内容"
